#ifndef __MATRIX_16_32_H__
#define __MATRIX_16_32_H__


/* For 32 Cathodes Red color columns */
#if defined(STM32F40x)
#define RED_RCC                     RCC_AHB1Periph_GPIOB
#else
#define RED_RCC                     RCC_APB2Periph_GPIOB
#endif
#define RED_COLUMN_PORT             GPIOB
#define RED_COLUMN_CLK_PIN          GPIO_Pin_15
#define RED_COLUMN_DATA_PIN         GPIO_Pin_14
#define RED_COLUMN_LATCH_PIN        GPIO_Pin_13

/* For 32 Cathodes Green color columns */
#if defined(STM32F40x)
#define GREEN_RCC                     RCC_AHB1Periph_GPIOA
#else
#define GREEN_RCC                     RCC_APB2Periph_GPIOA
#endif
#define GREEN_COLUMN_PORT           GPIOA
#define GREEN_COLUMN_CLK_PIN        GPIO_Pin_8
#define GREEN_COLUMN_DATA_PIN       GPIO_Pin_11
#define GREEN_COLUMN_LATCH_PIN      GPIO_Pin_12

/* For 16 Anodes */
#if defined(STM32F40x)
#define ROW_RCC                     RCC_AHB1Periph_GPIOC
#else
#define ROW_RCC                     RCC_APB2Periph_GPIOC
#endif
#define ROW_PORT                    GPIOC
#define ROW_CLK_PIN                 GPIO_Pin_3
#define ROW_DATA_PIN                GPIO_Pin_2
#define ROW_LATCH_PIN               GPIO_Pin_1

/* For Matrix power control pin */
#if defined(STM32F40x)
#define POWER_RCC                     RCC_AHB1Periph_GPIOB
#else
#define POWER_RCC                     RCC_APB2Periph_GPIOB
#endif
#define POWER_PORT                  GPIOB
#define POWER_PIN                   GPIO_Pin_8

#define MATRIX_HEIGHT               16
#define MATRIX_WEIGHT               32

/* DIM level */
enum xdim_level {
    LOW         = 0,
    MEDIUM      = 1,
    HIGH        = 2
};

/*  Column or Row Scan Mode */
enum xscan_matrix_mode {
    SCAN_COLUMN_MODE = 0,
    SCAN_ROW_MODE    = 1
    /* ... */
};

/*  Show image mode */
enum xshow_matrix_mode {
    MODE_0       = 0,
    MODE_1       = 1
    /* ... */
};

enum xpixel {
    OFF = 0,
    ON  = 1
};

enum matrix_color {
    RED = 0,
    GREEN   = 1,
    YELLOW  = 2
};

struct matrix_screen {
    unsigned char plane[MATRIX_HEIGHT][MATRIX_WEIGHT];
};

/* APIs */
#ifdef __cplusplus
extern "C" {
#endif

extern void matrix_init(void);
extern void matrix_green_show(char *pstring, enum xshow_matrix_mode mode);
extern void matrix_red_show( char *pstring, enum xshow_matrix_mode mode);
extern void matrix_clear_srceen(void);
extern void matrix_on(void);
extern void matrix_off(void);
extern void matrix_dim( enum xdim_level level );
extern void matrix_test(void);
extern void update_pixel(struct matrix_screen *screen, unsigned char row, unsigned char column, enum xpixel value);
extern void update_screen(struct matrix_screen *screen, enum xscan_matrix_mode mode, enum matrix_color color);

#ifdef __cplusplus
}
#endif

#endif